from collections import deque

def count_paths(grid, start, end):
    rows, cols = len(grid), len(grid[0])
    directions = [(0, 1), (0, -1), (1, 0), (-1, 0)]  # 上下左右移动

    queue = deque([start])
    visited = set([start])
    path_count = 0

    while queue:
        x, y = queue.popleft()
        if (x, y) == end:
            path_count += 1
            continue  # 如果找到了终点，继续查找下一个起点到终点的路径
        for dx, dy in directions:
            nx, ny = x + dx, y + dy
            if 0 <= nx < rows and 0 <= ny < cols and (nx, ny) not in visited and grid[nx][ny] != 'X':
                visited.add((nx, ny))
                queue.append((nx, ny))

    return path_count

# 假设这是你的地图
grid = [
    ['S', '.', '.', '.', '.', '.'],
    ['.', '.', '.', '.', '.', '.'],
    ['.', '.', '.', '.', '.', '.'],
    ['.', '.', '.', '.', '.', '.'],
    ['.', '.', '.', '.', '.', '.'],
    ['.', '.', '.', 'G', '.', '.']
]

start = (0, 0)  # 起点位置
end = (5, 3)    # 终点位置

print(count_paths(grid, start, end))  # 输出路径数量